#!coding=utf-8
from django.db import models
from django.contrib.auth.models import User,Group
from django.core.exceptions import ValidationError
from django.db.models.signals import pre_save, post_delete
class Technology(models.Model):
    #技术名称
    name=models.CharField(max_length=50)
    #技术大类
    type=models.CharField(max_length=50)
    #技术简介
    info=models.CharField(max_length=5000)
    #成熟性
    mature=models.NullBooleanField(null=True)
    #应用的适应性
    adaptation=models.CharField(max_length=1000)
    #应用的局限性
    limitation=models.CharField(max_length=1000)
    #国际应用情况
    internation_info=models.CharField(max_length=500)
    #国内应用案例
    case_info=models.CharField(max_length=5000)
    #污染物名称
    pollutant_name=models.CharField(max_length=50)
    #二次污染控制要点
    second_control_points=models.CharField(max_length=5000)
    #污染物浓度
    pollutant_concentration=models.CharField(max_length=10)
    #污染物列别
    pollutant_type=models.CharField(max_length=50)
    #时间
    refer_time=models.CharField(max_length=50)
    #具体时间
    input_time=models.CharField(max_length=50)
    #具体金额
    input_cost=models.CharField(max_length=50)
    #成本
    cost=models.CharField(max_length=20)
    #处置地点
    dispose=models.CharField(max_length=50)
    #污染物存在介质
    media=models.CharField(max_length=50)
    def __unicode__(self):
        return '%s' %self.name
    def return_dict(self):
        temp={}
        temp['id']=self.id
        temp['name']=self.name
        temp['type']=self.type
        if self.mature==True:
            self.mature='成熟'
        else:
            self.mature='不成熟'
        temp['mature']=self.mature
        temp['refer_time']=self.refer_time,self.input_time
        temp['cost']=self.cost,self.input_cost
        temp['media']=self.media
        #污染物名称
        temp['dispose']=self.dispose
        temp['pollutant_name']=self.pollutant_name
        #污染物列表选择
        temp['pollutant_type']=self.pollutant_type
        #污染物浓度
        temp['pollutant_concentration']=self.pollutant_concentration
        return temp
#资料链接
class  Date_link(models.Model):
    technology=models.ForeignKey(Technology)
    link=models.CharField(max_length=100)
    def __unicode__(self):
        return '%s-%s' %(self.technology,self.link)

class Image(models.Model):
    technology=models.ForeignKey(Technology)
    imagename=models.CharField(verbose_name=u'图片名称',max_length=100)
    image=models.ImageField(upload_to='attachment/images/%Y/%m/%d',null=True,blank=True)

class UploadFile(models.Model):
    technology=models.ForeignKey(Technology)
    filename=models.CharField(max_length=100,null=True,blank=True)
    upload_file=models.FileField(upload_to='attachment/files/%Y/%m/%d')

class MyUserModel(models.Model):
    username = models.CharField(u'用户名',max_length=60, unique=True)
    password = models.CharField(u'密码',max_length=60)
    name = models.CharField(u'姓名',max_length=60)
    #remark = models.TextField(u'备注',blank=True,null=True)
    user_id = models.IntegerField(u'用户id',null=True)
    is_staff=models.BooleanField(u'帐号为管理员',default=True,help_text=u'无效请取消勾选')
    is_active = models.BooleanField(u'帐号是否有效',default=True,help_text=u'无效请取消勾选')

